<?php

namespace backend\controllers;

use common\models\SystemConfig;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;

class BaseController extends Controller
{

    /**
     * 从数据库加载配置
     * 推送 短信 邮件等的配置文件
     */
    public function init()
    {
        parent::init();
    }

    /**
     * @return array
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::class,
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['@'], // 登录
                    ],
                ],
            ],
        ];
    }

    /**
     * 记录访问日志等
     *
     * @param $action
     * @return bool
     * @throws \yii\web\BadRequestHttpException
     */

    public function beforeAction($action): bool
    {
        return parent::beforeAction($action);
    }




    public function message($msgText, $skipUrl, $msgType = null)
    {
        if (!$msgType || !in_array($msgType, ['success', 'error', 'info', 'warning'])) {
            $msgType = 'success';
        }

        Yii::$app->getSession()->setFlash($msgType, $msgText);
        return $skipUrl;
    }


}
